﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class TipManager : BaseManager {
    //是否显示性能信息
    public bool openPerfermanceInfo = false;

    public bool closeTip = true;

    private float vSliderValue = 0.0f;
    private float hSliderValue = 0.0f;
    public Vector2 scrollPosition = Vector2.zero;
    private List<string> tipList = new List<string>();
    private string _tip;
    //public GUIStyle customGuiHStyle = new GUIStyle();
    //public GUIStyle customGuiVStyle = new GUIStyle();

    private FPSCounter fpsCounter;
	void Start () {
        _tip = "";
        fpsCounter = new FPSCounter();
	}

    public void SetTip(string content) {
        tipList.Add(content);
    }

    //IMGUI
    void OnGUI()
    {
        if (MainConst.DebugMode)
        {
            closeTip = GUI.Toggle(new Rect(0, 100, 100, 100), closeTip, new GUIContent("调试模式"));
        }

        if (!MainConst.DebugMode)
        {
            return;
        }

        if (!closeTip)
        {
            //创建背景框
            GUI.Box(new Rect(0, 120, 780, 300), "调试窗口");
            //创建一个大按钮遮挡底层点击事件传递,需要在if判断下才能阻挡
            if (GUI.Button(new Rect(0, 120, 780, 300), ""))
            {

            }
            GUIStyle titleStyle = new GUIStyle();
            titleStyle.fontSize = 20;
            titleStyle.normal.textColor = Color.green;
            GUIStyle borderStyle = new GUIStyle();
            borderStyle.CalcHeight(null, 100);

            //改变scrollview bar的宽高 方便手机调试时点击,改变会更新本地的style数据，包括在运行时修改参数也会直接修改本地style数据
            //GUISkin skin = GUI.skin;
            //customGuiHStyle = skin.horizontalScrollbar;
            //customGuiVStyle = skin.verticalScrollbar;
            //customGuiHStyle.fixedHeight = 15;
            //customGuiVStyle.fixedWidth = 15;

            //第一个rect:滚动框的占据的区域大小;第二个:可显示的内容的大小，即每一个item的大小
            scrollPosition = GUI.BeginScrollView(new Rect(10, 130, 800, 300), scrollPosition, new Rect(0, 0, 2000, (tipList.Count + 10) * 30), false, false);//, true, true, customGuiHStyle, customGuiVStyle

            for (int i = 0; i < tipList.Count; i++)
            {
                GUI.Label(new Rect(0, i * 50, 1000, 30), tipList[i], titleStyle);
            }
            GUI.EndScrollView();
            if (GUI.Button(new Rect(120, 100, 100, 20), "clear"))
            {
                tipList.Clear();
                _tip = "";
            }
            if (GUI.Button(new Rect(240, 100, 100, 20), "Add More Text"))
            {
                tipList.Add("\nHere is another line");
            }
        }

        if (MainConst.DebugMode)
        {
            openPerfermanceInfo = GUI.Toggle(new Rect(0, 70, 100, 100), openPerfermanceInfo, new GUIContent("显示DC等信息"));
        }
        if (openPerfermanceInfo)
        {
            fpsCounter.Update();

            GUILayout.TextField("Total DrawCall: " + UnityStats.drawCalls);
            GUILayout.TextField("Batch: " + UnityStats.batches);
            GUILayout.TextField("Static Batch DC: " + UnityStats.staticBatchedDrawCalls);
            GUILayout.TextField("Static Batch: " + UnityStats.staticBatches);
            GUILayout.TextField("DynamicBatch DC: " + UnityStats.dynamicBatchedDrawCalls);
            GUILayout.TextField("DynamicBatch: " + UnityStats.dynamicBatches);
            GUILayout.TextField("Tri: " + UnityStats.triangles);
            GUILayout.TextField("Ver: " + UnityStats.vertices);
            GUILayout.TextField("FPS: " + fpsCounter.FPS);
        }

    }
}
